home *** CD-ROM | disk | FTP | other *** search
/ Resource for Source: C/C++ / Resource for Source - C-C++.iso / codelib8 / v_10_04 / 1004010d < prev    next >
Encoding:
Text File  |  1995-11-01  |  351 b   |  17 lines

  1. /* ldiv function */
  2. #include <stdlib.h>
  3.  
  4. ldiv_t (ldiv)(long numer, long denom)
  5.     {    /* compute long quotient and remainder */
  6.     ldiv_t val;
  7.  
  8.     val.quot = numer / denom;
  9.     val.rem = numer - denom * val.quot;
  10.     if (val.quot < 0 && 0 < val.rem)
  11.         {    /* fix remainder with wrong sign */
  12.         val.quot += 1;
  13.         val.rem -= denom;
  14.         }
  15.     return (val);
  16.     }
  17.